package com.zzhou.linkinfo.clock.activity;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.zzhou.linkinfo.clock.R;
import com.zzhou.linkinfo.clock.activity.base.AbstractTitleActivity;
import com.zzhou.linkinfo.clock.adapter.ClockMainAdapter;
import com.zzhou.linkinfo.clock.entity.TaskBean;
import com.zzhou.linkinfo.clock.mvp.clockmain.IMainContract;
import com.zzhou.linkinfo.clock.mvp.clockmain.MainPresenter;

import java.util.List;

public class ClockMainActivity extends AbstractTitleActivity implements IMainContract.IView{

    private XRecyclerView mRecyclerView;
    private Button mEnterReleaseTaskBtn;
    private TextView testTv;

    private ClockMainAdapter mAdapter;
    private IMainContract.APresenter mPresenter;

    @Override
    protected int attachLayoutRes() {
        return R.layout.clock_activity_main;
    }

    @Override
    protected void initView() {
        mPresenter = new MainPresenter(this);
        mRecyclerView = findViewById(R.id.clock_main_recycleView);

        mEnterReleaseTaskBtn = findViewById(R.id.release_task_btn);
        testTv = findViewById(R.id.clock_main_testTv);

        mEnterReleaseTaskBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ClockMainActivity.this, ClockReleaseTaskActivity.class);
                startActivity(intent);
            }
        });
        initRecycleView();
        mPresenter.request();
    }

    @Override
    public void onShowResult(boolean isSuccess, List<TaskBean> list) {
        testTv.setText(list.toString());
    }

    private void initRecycleView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new ClockMainAdapter(this);
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setClockListener(new ClockMainAdapter.OnClickClockMainListener() {
            @Override
            public void onClickItemView(int position) {

            }

            @Override
            public void onClickEntance(int position) {

            }
        });
    }
}
